<!DOCTYPE html>
<html>
<head>
  <title>Domain.java</title>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/>
  <link rel='stylesheet' type='text/css' href='../../../../../../coverage.css'/>
  <link rel='shortcut icon' type='image/png' href='../../../../../../logo.png'/>
  <script type='text/javascript' src='../../../../../../coverage.js'></script>
  <script type='text/javascript' src='../../../../../../prettify.js'></script>
</head>
<body onload='prettyPrint()'>
  <table cellpadding='0' cellspacing='1'>
    <caption>igraph_client_java/src/main/java/com/taobao/igraph/vipserver/client/core/Domain.java</caption>
    <tr>
      <td class='line'>1</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>package com.taobao.igraph.vipserver.client.core;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'></td><td>&nbsp;</td>
      <td><pre class='imports prettyprint' onclick='showHideLines(this)'><div>import com.google.gson.annotations.SerializedName;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;
</div><span>import ...</span></pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>10</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>public class Domain {</pre></td>
    </tr>
    <tr>
      <td class='line'>11</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static final String SPLITER = "@@";</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>13</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    @SerializedName("dom")</pre></td>
    </tr>
    <tr>
      <td class='line'>14</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String name;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>16</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String clusters;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>18</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private long cacheMillis = 1000L;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>20</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private List&lt;Host> hosts = new ArrayList&lt;Host>();</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>22</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private long lastRefTime = 0L;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>24</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    private String checksum = StringUtils.EMPTY;</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>26</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public Domain() {}</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>28</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public Domain(String key) {</pre></td>
    </tr>
    <tr>
      <td class='line'>29</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        String[] keys = key.split(SPLITER);</pre></td>
    </tr>
    <tr>
      <td class='line'>30</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (keys.length >= 2) {</pre></td>
    </tr>
    <tr>
      <td class='line'>31</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            this.name = keys[0];</pre></td>
    </tr>
    <tr>
      <td class='line'>32</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            this.clusters = keys[1];</pre></td>
    </tr>
    <tr>
      <td class='line'>33</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>35</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.name = keys[0];</pre></td>
    </tr>
    <tr>
      <td class='line'>36</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>38</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public Domain(String name, String clusters) {</pre></td>
    </tr>
    <tr>
      <td class='line'>39</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.name = name;</pre></td>
    </tr>
    <tr>
      <td class='line'>40</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.clusters = clusters;</pre></td>
    </tr>
    <tr>
      <td class='line'>41</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>43</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public int ipCount() {</pre></td>
    </tr>
    <tr>
      <td class='line'>44</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return hosts.size();</pre></td>
    </tr>
    <tr>
      <td class='line'>45</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>47</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public boolean expired() {</pre></td>
    </tr>
    <tr>
      <td class='line'>48</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return System.currentTimeMillis() - lastRefTime > cacheMillis;</pre></td>
    </tr>
    <tr>
      <td class='line'>49</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>51</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void setHosts(List&lt;Host> hosts) {</pre></td>
    </tr>
    <tr>
      <td class='line'>52</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.hosts = hosts;</pre></td>
    </tr>
    <tr>
      <td class='line'>53</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>55</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public boolean isValid() {</pre></td>
    </tr>
    <tr>
      <td class='line'>56</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return hosts != null;</pre></td>
    </tr>
    <tr>
      <td class='line'>57</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>59</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public String getName() {</pre></td>
    </tr>
    <tr>
      <td class='line'>60</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return name;</pre></td>
    </tr>
    <tr>
      <td class='line'>61</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>63</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void setName(String name) {</pre></td>
    </tr>
    <tr>
      <td class='line'>64</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.name = name;</pre></td>
    </tr>
    <tr>
      <td class='line'>65</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>67</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void setLastRefTime(long lastRefTime) {</pre></td>
    </tr>
    <tr>
      <td class='line'>68</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.lastRefTime = lastRefTime;</pre></td>
    </tr>
    <tr>
      <td class='line'>69</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>71</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public long getLastRefTime() {</pre></td>
    </tr>
    <tr>
      <td class='line'>72</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return lastRefTime;</pre></td>
    </tr>
    <tr>
      <td class='line'>73</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>75</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public String getClusters() {</pre></td>
    </tr>
    <tr>
      <td class='line'>76</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return clusters;</pre></td>
    </tr>
    <tr>
      <td class='line'>77</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>79</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void setClusters(String clusters) {</pre></td>
    </tr>
    <tr>
      <td class='line'>80</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.clusters = clusters;</pre></td>
    </tr>
    <tr>
      <td class='line'>81</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>83</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public long getCacheMillis() {</pre></td>
    </tr>
    <tr>
      <td class='line'>84</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return cacheMillis;</pre></td>
    </tr>
    <tr>
      <td class='line'>85</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>87</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void setCacheMillis(long cacheMillis) {</pre></td>
    </tr>
    <tr>
      <td class='line'>88</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.cacheMillis = cacheMillis;</pre></td>
    </tr>
    <tr>
      <td class='line'>89</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>91</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public List&lt;Host> getHosts() {</pre></td>
    </tr>
    <tr>
      <td class='line'>92</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return new ArrayList&lt;Host>(hosts);</pre></td>
    </tr>
    <tr>
      <td class='line'>93</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>95</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public boolean validate() {</pre></td>
    </tr>
    <tr>
      <td class='line'>96</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (CollectionUtils.isEmpty(hosts)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>97</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return false;</pre></td>
    </tr>
    <tr>
      <td class='line'>98</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>100</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        List&lt;Host> validHosts = new ArrayList&lt;Host>();</pre></td>
    </tr>
    <tr>
      <td class='line'>101</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        for (Host host : hosts) {</pre></td>
    </tr>
    <tr>
      <td class='line'>102</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            if (!host.isValid()) {</pre></td>
    </tr>
    <tr>
      <td class='line'>103</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                continue;</pre></td>
    </tr>
    <tr>
      <td class='line'>104</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>106</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            for (int i = 0; i &lt; host.getWeight(); i++) {</pre></td>
    </tr>
    <tr>
      <td class='line'>107</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>                validHosts.add(host);</pre></td>
    </tr>
    <tr>
      <td class='line'>108</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            }</pre></td>
    </tr>
    <tr>
      <td class='line'>109</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>111</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (CollectionUtils.isEmpty(validHosts)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>112</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return false;</pre></td>
    </tr>
    <tr>
      <td class='line'>113</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>115</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return true;</pre></td>
    </tr>
    <tr>
      <td class='line'>116</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>118</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public String getKey() {</pre></td>
    </tr>
    <tr>
      <td class='line'>119</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return getKey(name, clusters);</pre></td>
    </tr>
    <tr>
      <td class='line'>120</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>122</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public static String getKey(String name, String clusters) {</pre></td>
    </tr>
    <tr>
      <td class='line'>123</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        if (!StringUtils.isEmpty(clusters)) {</pre></td>
    </tr>
    <tr>
      <td class='line'>124</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>            return name + SPLITER + clusters;</pre></td>
    </tr>
    <tr>
      <td class='line'>125</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>127</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return name;</pre></td>
    </tr>
    <tr>
      <td class='line'>128</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>130</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    @Override</pre></td>
    </tr>
    <tr>
      <td class='line'>131</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public String toString() {</pre></td>
    </tr>
    <tr>
      <td class='line'>132</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return getKey();</pre></td>
    </tr>
    <tr>
      <td class='line'>133</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>135</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public String getChecksum() {</pre></td>
    </tr>
    <tr>
      <td class='line'>136</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        return checksum;</pre></td>
    </tr>
    <tr>
      <td class='line'>137</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr><td class='line'></td><td colspan='2'>&nbsp;</td></tr>
    <tr>
      <td class='line'>139</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    public void setChecksum(String checksum) {</pre></td>
    </tr>
    <tr>
      <td class='line'>140</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>        this.checksum = checksum;</pre></td>
    </tr>
    <tr>
      <td class='line'>141</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>    }</pre></td>
    </tr>
    <tr>
      <td class='line'>142</td><td>&nbsp;</td>
      <td><pre class='prettyprint'>}</pre></td>
    </tr>
  </table>
</body>
</html>
